﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.SessionState;

/// <summary>
///frontCurrentStu 的摘要说明
/// </summary>
public static class frontCurrentStu
{

    
    //TODO: 在此处添加构造函数逻辑
    //
    /// <summary>
    /// 得到学生信息ID
    /// </summary>
    /// <returns></returns>
    public static int GetUserID()
    {

        HttpSessionState tempSession = System.Web.HttpContext.Current.Session;
        //此处应当使用session

        if (tempSession["StudentID"] == null)
        {
           
            return -1;

            // return -1;//throw new ApplicationException("出错了!未登录，或session已经过期!");


        }
        else
        {
            return Convert.ToInt32(tempSession["StudentID"]);
        }


    }
    /// <summary>
    /// 登录名，即学生学号
    /// </summary>
    /// <returns></returns>
    public static string GetNo()
    {




        HttpSessionState tempSession = System.Web.HttpContext.Current.Session;
        //此处应当使用session

        if (tempSession["StuNo"] == null)
        {
            return "";
            // return String.Empty ;// throw new ApplicationException("出错了!未登录，或session已经过期!");


        }
        else
        {
            return (string)tempSession["StuNo"];
        }


    }


    /// <summary>
    /// 得到学期ID
    /// </summary>
    /// <returns></returns>
    public static int GetCurrentTerm()
    {

        HttpSessionState tempSession = System.Web.HttpContext.Current.Session;
        //此处应当使用session

        if (tempSession["TermID"] == null)
        {
            //return 3;
            return -1;

            // return -1;//throw new ApplicationException("出错了!未登录，或session已经过期!");


        }
        else
        {
            return Convert.ToInt32(tempSession["TermID"]);
        }


    }



    /// <summary>
    /// 取当前用户的用户名
    /// </summary>
    /// <returns></returns>
    public static string GetUserName()
    {

        HttpSessionState tempSession = System.Web.HttpContext.Current.Session;
        //此处应当使用session

        if (tempSession["StuName"] == null)
        {
            return "";
            // return String.Empty ;// throw new ApplicationException("出错了!未登录，或session已经过期!");


        }
        else
        {
            return (string)tempSession["StuName"];
        }

    }




    /// <summary>
    /// 得到当前的学生专业代码
    /// </summary>
    /// <returns></returns>
    public static int GetPartCode()
    {
        HttpSessionState tempSession = System.Web.HttpContext.Current.Session;
        //此处应当使用session
        if (tempSession["StuProCode"] == null)
        {
            return -1;
        }
        else
        {
            return Convert.ToInt32(tempSession["StuProCode"]);
        }

    }


    /// <summary>
    /// 取得当前用户类型，0学生，1教师，2管理员，3所有用户
    /// </summary>
    /// <returns></returns>
    public static string GetUserType()
    {
        HttpSessionState tempSession = System.Web.HttpContext.Current.Session;
        if (!string.IsNullOrEmpty(tempSession["UserType"].ToString()))
        {
            string UserType = tempSession["UserType"].ToString();
            return UserType;
        }
        return "";
    }


    /// <summary>
    /// 获取考试状态
    /// </summary>
    /// <returns></returns>
    public static int TestState()
    {

        HttpSessionState tempSession = System.Web.HttpContext.Current.Session;
        //此处应当使用session

        if (tempSession["TestCourseID"] == null)
        {
            return -1;//当前没有考试
            // return String.Empty ;// throw new ApplicationException("出错了!未登录，或session已经过期!");
        }
        else
        {
            return Convert.ToInt32(tempSession["TestCourseID"]);
        }
    }

    /// <summary>
    /// 清除Session
    /// </summary>
    public static void ClearSession()
    {
        HttpSessionState tempSession = System.Web.HttpContext.Current.Session;
        tempSession.Clear();
    }



}
